package com.colin.project.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 静态资源映射
 */
@Component
public class MvcConfig implements WebMvcConfigurer {

    //实际地址
    @Value("${my.project.user.head-img.resource-location}")
    private String headImgResourceLocation;

    //虚拟地址
    @Value("${my.project.user.head-img.resource-handler}")
    private String headImgResourceHandler;

    //将虚拟地址映射到真实地址
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry
                .addResourceHandler(headImgResourceHandler + "**")
                .addResourceLocations("file:///" + headImgResourceLocation);
    }
}
